package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func printFile(filename string) {
	file, err := os.Open(filename)
	if err != nil {
		panic(err)
	}

	printFileContent(file)
}
func printFileContent(reader io.Reader) {
	// 按行读取
	scanner := bufio.NewScanner(reader)
	for scanner.Scan() {
		fmt.Println(scanner.Text())
	}
}

// 返回整数类型的二进制字符串
func convertToBin(n int) string {
	result := ""
	for ; n > 0; n /= 2 {
		lsb := n % 2
		result = strconv.Itoa(lsb) + result
	}
	return result
}

func main() {
	fmt.Println("abc.txt contents is:")
	printFile("base/branch/abc.txt")

	fmt.Println(convertToBin(3))
	fmt.Println(convertToBin(13))

	s := `abc
	bcd
	cde
	`
	printFileContent(strings.NewReader(s))
}
